﻿using System.Windows.Input;
using CiStatus.CiStatusAddIn.Logic;
using CiStatus.CiStatusAddIn.Logic.Commands;
using CiStatus.CiStatusAddIn.Logic.Status;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace CiStatus.CiStatusAddIn.ViewModels
{
    public class ProjectViewModel
    {
        private readonly IProject _project;

        public ProjectViewModel(IProject project)
        {
            _project = project;
            ShowLinkCommand = new DelegateCommand(ShowLink, CanShowLink);
        }

        public ProjectViewModel()
        {}

        private bool CanShowLink(object arg)
        {
            return true;
        }

        private void ShowLink(object obj)
        {
            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
            dte.ItemOperations.Navigate(_project.Parameters["Link"].Value);
        }

        public Status CurrentStatus
        {
            get
            {
                return (Status) _project.CurrentStatus;
            }
        }

        public Status PreviousStatus
        {
            get
            {
                return (Status)_project.PreviousStatus;
            }
        }

        public SettingViewModel SettingViewModel
        {
            get
            {
                return new SettingViewModel(_project.Parameters);
            }
        }

        public ICommand ShowLinkCommand { get; set; }
    }
}